<template>
  <div class="nameList_box">
    <div class="search_view">
      <div class="search">
        <input type="text" value="" id="name" placeholder="请输入艺人姓名/艺名"/>
        <div class="search_text" @click="onSearch"><span>搜索</span></div>
        <div style="width: 1px;height:30px;background: white "/>
        <div class="search_all_text" @click="getActorsList"><span>清除选项</span></div>
      </div>
      <div>
        <button class="buttonStyle" @click="pushToAdd">添加</button>
      </div>
    </div>
    <div class="first_box">
      <div class="first" v-for='item, index in actorsList' @click="pushToDetail(index)">
        <div class="first_img">
          <img :src="item.cover"/>
        </div>
        <div class="first_text">
          <div class="text_one">
            <div class="text_one_one">
              <span style="font-size: 20px">{{item.realName}}</span>
              <span>{{item.sex == 1 ? '男' : '女'}}</span>
              <span>{{item.score}}</span>
            </div>
            <div class="text_one_two">
              <img @click.stop @click="onCollect(item.uid)" v-show="item.isCollect == 0"
                   src="../../assets/collect_normal.png" alt/>
              <img @click.stop @click="onDeleteCollect(item.collectID)" v-show="item.isCollect == 1"
                   src="../../assets/collect_selected.png" alt/>
            </div>
          </div>
          <div class="text_two">
            <div class="text_one_one">
              <span>{{item.age}}岁</span> <span>{{item.height}}cm</span> <span>{{item.weight}}kg</span>
            </div>
            <span></span>
          </div>
          <p>职业：{{item.jobList}}</p>
          <p>地址：{{item.cityList}}</p>
          <p>标签：{{item.typeList}}</p>
          <div class="split"></div>
          <div class="bottom">
            <span class="auditing" v-show="item.isAudit == 0">待审核</span>
            <span class="audit-success" v-show="item.isAudit == 1">通过</span>
            <span class="audit-fail" v-show="item.isAudit == 2">不通过</span>
            <span @click.stop @click="open2(item.uid)">删除</span>
          </div>
        </div>
        <div>
        </div>
      </div>
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage4"
          :page-size="12"
          layout="prev, pager, next, jumper"
          :total="rowsCount"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        activeName: "first",
        actorsList: [],
        rowsCount: 0,
        page: 1,
        selectList: []
      };
    },
    mounted: function () {
      this.getActorsList();
    },
    methods: {
      pushToAdd() {
        this.$router.push({path: '/artistAdd', query: {type: 'add'}});
      },
      pushToDetail(index) {
        let routeData = this.$router.resolve({
          path: "/newArtistDetail",
          query: {uid: this.actorsList[index].uid, isOperation: this.actorsList[index].isOperation}
        });
        window.open(routeData.href, '_blank');
      },
      handleClick(tab, event) {
        console.log(tab, event);
      },
      getActorsList: function () {
        document.getElementById("name").value = '';
        let self = this;
        let obj = {
          token: self.globalData.token,
          columnCID: '2',
          pageSize: '12',
          page: this.page,
        };
        self.$post("/User/getUserActor", obj).then(res => {
          if (res.code === "200") {
            self.actorsList = res.data.userList;
            self.rowsCount = res.data.rowsCount;
          } else {
            self.$message.error(res.message);
          }
        });
      },
      open2(id) {
        let self = this;
        this.$confirm('是否要删除该艺人?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          self.deleteActor(id);
        }).catch(() => {

        });
      },
      deleteActor(id) {
        let self = this;
        let obj = {
          token: self.globalData.token,
          actorUid: id
        };
        self.$fetch("/User/deleteUserActor", obj).then(res => {
          if (res.code === "200") {
            self.$message("删除成功");
            self.getActorsList();
          } else {
            self.$message.error(res.message);
          }
        });
      },
      onCollect(id) {
        let self = this;
        let obj = {
          token: self.globalData.token,
          actorUid: id
        };
        self.$fetch("/User/createCollect", obj).then(res => {
          if (res.code === "200") {
            self.$message("收藏成功");
            self.getActorsList();
          } else {
            self.$message.error(res.message);
          }
        });
      },
      onDeleteCollect(collectID) {
        let self = this;
        let obj = {
          token: self.globalData.token,
          collectID: collectID
        };
        self.$fetch("/User/deleteCollect", obj).then(res => {
          if (res.code === "200") {
            self.$message("取消收藏成功");
            self.getActorsList();
          } else {
            self.$message.error(res.message);
          }
        });
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.page = val;
        this.getActorsList();
      },
      onSearch() {
        var keywords = document.getElementById("name").value;
        if (keywords === '') {
          this.$message.error('请输入艺人姓名/艺名');
        } else {
          let self = this;
          let obj = {
            token: self.globalData.token,
            columnCID: '2',
            pageSize: '12',
            page: this.page,
            keywords: keywords
          };
          self.$post("/User/getUserActor", obj).then(res => {
            if (res.code === "200") {
              self.actorsList = res.data.userList;
              self.rowsCount = res.data.rowsCount;
            } else {
              self.$message.error(res.message);
            }
          });
        }
      }
    }
  }
  ;
</script>

<style lang="less" scoped>
  .nameList_box {
    width: 80%;
    margin: auto;
    font-size: 12px;
    .first_box {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      margin-top: 20px;
      width: 100%;
      .first {
        position: relative;
        margin-top: 40px;
        margin-left: 20px;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        flex: 0 1 calc(33% - 30px);
        height: auto;
        border-radius: 4px;
        border: 1px solid #f0f0f0;
        box-shadow: 0 3px 13px 0px rgba(0, 0, 0, 0.1);
        .first_img {
          width: 40%;
          height: auto;
          position: relative;
          top: -10px;
          left: -10px;
          img {
            top: -10px;
            left: -10px;
            height: auto;
            width: 100%;
            border-radius: 10px;
          }
        }
        .first_text {
          width: 60%;
          height: auto;
          display: flex;
          flex-direction: column;
          .text_one {
            padding: 10px 15px 0px 0px;
            // width: 100%;
            display: flex;
            flex-direction: row;
            align-content: center;
            justify-content: space-between;
            img {
              width: 18px;
              height: auto;
            }
            .text_one_one {
              display: flex;
              align-items: center;
              justify-content: space-between;
              width: 100%;
            }
          }
          .text_two {
            padding: 10px 15px 0px 0px;

            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
          }
        }
        .out {
          border-top: 1px solid #f0f0f0;
          width: 100%;
          height: 36px;
          padding-right: 15px;
          text-align: right;
          line-height: 30px;
        }
        .split {
          width: 94%;
          height: 1px;
          background-color: #f2f2f2;
        }
      }
      .bottom {
        flex: 1;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 10px 20px;
        .auditing {
          border-width: 1px;
          background: white;
          color: red;
          border-color: red;
        }
        .audit-success {
          border-width: 1px;
          background: white;
          color: black;
          border-color: black;
          font-width: 3px;
        }
        .audit-fail {
          border-width: 1px;
          background: white;
          color: red;
          border-color: red;
        }
      }
    }
  }

  p {
    display: -webkit-box;
    /*! autoprefixer: off */
    -webkit-box-orient: vertical;
    /* autoprefixer: on */
    -webkit-line-clamp: 1;
    overflow: hidden;
    padding-right: 10px;
    text-overflow: ellipsis;
  }

  .search_view {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #f7f8fa;
    padding: 10px;
  }

  .search {
    display: flex;
    flex-direction: row;
    align-items: center;
    input {
      width: 200px;
      border-top-left-radius: 10px;
      border-bottom-left-radius: 10px;
      height: 26px;
      padding-left: 16px;
      color: black;
      border: 1px solid #f7f8fa;
      font-size: 12px;
      background-color: #f0f0f0;
      outline: none;
    }
    .search_all_text {
      background-color: #8c94a7;
      height: 30px;
      width: 100px;
      border-top-right-radius: 10px;
      border-bottom-right-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      span {
        font-size: 12px;
        color: white;
        letter-spacing: 0.6px;
      }
    }
    .search_text {
      background-color: #8c94a7;
      height: 30px;
      width: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      span {
        font-size: 12px;
        color: white;
        letter-spacing: 0.6px;
      }
    }
  }

  .buttonStyle {
    padding: 0px 20px;
    background-color: #bd2f2e;
    color: white;
    height: 30px;
    border-radius: 4px;
  }
</style>
